import requests as req;
import os;

if __name__ == '__main__':

    if(not os.path.exists("bug_file")):
        os.mkdir("bug_file");

    url = "https://www.baidu.com/s";
    key = input("请输入想要搜索的关键词:");
    params = {
        "wd":key
    }

    # UA伪装
    header = {
        "User-Agent":"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.88 Safari/537.36",
        "Mobile-User-Agent":"Mozilla/5.0 (Linux; Android 5.0; SM-G900P Build/LRX21T) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.88 Mobile Safari/537.36"
    }

    result = req.get(url=url,params=params,headers=header);

    file_name = "爬虫-百度-"+key+".html";
    with open("./bug_file/"+file_name,"w",encoding="utf-8") as wf:
        wf.write(result.text);

    print(file_name,"采集完毕!!");